package com.example.list;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import mvp.MVPActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.animation.AnimationSet;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.demo.viewpager.VPMainActivity;
import com.example.androidxtest.lazy.androidxLazyActivity;
import com.example.haohao.myview.FengChe2Activity;
import com.example.haohao.myview.FlowActivity;
import com.example.haohao.myview.MyViewMainActivity;
import com.example.haohao.myview.ProgressBarActivity;
import com.example.haohao.myview.ReflectActivity;
import com.example.haohao.myview.ShowMyViewActivity;
import com.example.haohao.myview.expandView.MyExpandActivity;
import com.example.haohao.myview.joker.TestActivity;
import com.example.kotlinview.JsonObjectActivity;
import com.example.kotlinview.KotlinActivity;
import com.example.list.bigbang.BigBangActivity;
import com.example.list.four_basic_component.BasicComponentActivity;
import com.example.list.jetpack.WorkManagerActivity;
import com.example.list.kunkun.KunKunActivity;
import com.example.list.lazyload.LazyLoadActivity;
import com.example.list.recyleview.ListActivity;
import com.example.list.service_demo.BindServiceActivity;
import com.example.list.share.ShareActivity;
import com.example.list.simple_calendar.SimpleCalendarActivity;
import com.example.list.sqlite.SQLiteActivity;
import com.example.list.swiperefresh.SwipeRefreshActivity;
import com.example.mvptest.JokeActivity;
import com.example.mvptest.MessageWrap;
import com.example.utils.DispUtil;
import com.example.vpdemo.MaterialMainActivity;
import com.orhanobut.logger.Logger;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity  {


    private RecyclerView rl;
    final ArrayList<MyClassBean> myClassList = new ArrayList<MyClassBean>();

    /**
     * 添加列表数据
     */
    private void initData() {

        myClassList.add(new MyClassBean("vivo桌面图标权限", vivoShortcutPermissionActivity.class));
        myClassList.add(new MyClassBean("androidx懒加载", androidxLazyActivity.class));
        myClassList.add(new MyClassBean("EdittextPast", EdittextPastActivity.class));
        myClassList.add(new MyClassBean("WebViewActivity2", WebViewActivity2.class));
        myClassList.add(new MyClassBean("WebViewActivity", WebViewActivity.class));
        myClassList.add(new MyClassBean("GetResourceActivity", GetResourceActivity.class));
        myClassList.add(new MyClassBean("JsonObject", JsonObjectActivity.class));
        myClassList.add(new MyClassBean("kunkun", KunKunActivity.class));
        myClassList.add(new MyClassBean("Kotlin", KotlinActivity.class));
        myClassList.add(new MyClassBean("ShapeOutActivity", ShapeOutActivity.class));
        myClassList.add(new MyClassBean("SpinnerActivity", SpinnerActivity.class));
        myClassList.add(new MyClassBean("TextviewClickActivity", TextviewClickActivity.class));
        myClassList.add(new MyClassBean("FlowActivity", FlowActivity.class));
        myClassList.add(new MyClassBean("LinearLayoutBottomActivity", LinearLayoutBottomActivity.class));
        myClassList.add(new MyClassBean("MyViewActivity", ShowMyViewActivity.class));
        myClassList.add(new MyClassBean("简繁体适配", InternationalActivity.class));
        myClassList.add(new MyClassBean("listview", ListViewActivity.class));
        myClassList.add(new MyClassBean("进度条", ProgressBarActivity.class));
        myClassList.add(new MyClassBean("懒加载", LazyLoadActivity.class));
        myClassList.add(new MyClassBean("动态布局", DynamicViewActivity.class));
        myClassList.add(new MyClassBean("日历", CalendarActivity.class));
        myClassList.add(new MyClassBean("Dialog", DialogActivity.class));
        myClassList.add(new MyClassBean("简单日历", SimpleCalendarActivity.class));
        myClassList.add(new MyClassBean("Sqlite数据库", SQLiteActivity.class));
        myClassList.add(new MyClassBean("反射", ReflectActivity.class));
        myClassList.add(new MyClassBean("layer-list", LayerListActivity.class));
        myClassList.add(new MyClassBean("帧布局", FrameLayoutActivity.class));
        myClassList.add(new MyClassBean("tvSpannableStringBuilder", SpannableStringBuilderActivity.class));
        myClassList.add(new MyClassBean("popWindow(Basic)", PopwinBasicActivity.class));
        myClassList.add(new MyClassBean("popWindow", PoppupWindowActivity.class));
        myClassList.add(new MyClassBean("tab", TablayoutActivity.class));
        myClassList.add(new MyClassBean("RecyclView", ListActivity.class));
        myClassList.add(new MyClassBean("BasicComponentActivity", BasicComponentActivity.class));
        myClassList.add(new MyClassBean("WorkManagerActivity", WorkManagerActivity.class));
        myClassList.add(new MyClassBean("VpDemo", VPMainActivity.class));
        myClassList.add(new MyClassBean("retrofitDemo", TestActivity.class));
        myClassList.add(new MyClassBean("MyViwe", MyViewMainActivity.class));

        myClassList.add(new MyClassBean("风车2", FengChe2Activity.class));
        myClassList.add(new MyClassBean("MaterialDesign", MaterialMainActivity.class));
        myClassList.add(new MyClassBean("onekeyShare", ShareActivity.class));
        myClassList.add(new MyClassBean("BindService", BindServiceActivity.class));
        myClassList.add(new MyClassBean("mvp", MVPActivity.class));
        myClassList.add(new MyClassBean("mvp2", JokeActivity.class));
        myClassList.add(new MyClassBean("AddView", AddViewActivity.class));
        myClassList.add(new MyClassBean("AddView2,动态修改视图", AddViewActivity2.class));
        myClassList.add(new MyClassBean("刷新", SwipeRefreshActivity.class));
        myClassList.add(new MyClassBean("BigBang", BigBangActivity.class));
        myClassList.add(new MyClassBean("popupwindow2", MyExpandActivity.class));
        myClassList.add(new MyClassBean("btnbg", BtnBgActivity.class));
//        myClassList.add(new MyClassBean("Note", NoteActivity.class));
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        Resources resources = getResources();
//        Configuration configuration = resources.getConfiguration();
//        configuration.fontScale = 1.0f;//0.85:小号  1:标准  1.25:大号  1.4:巨无霸
//        resources.updateConfiguration(configuration, resources.getDisplayMetrics());

        DispUtil.disabledDisplayDpiChange(this.getResources());

        setContentView(R.layout.activity_main);

        EventBus.getDefault().register(this);
        rl = (RecyclerView) findViewById(R.id.rl);

        final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        rl.setLayoutManager(layoutManager);


        initData();

        final ClassAdapter adapter = new ClassAdapter(this, myClassList);
        rl.setAdapter(adapter);
//        rl.setDivider(getContext().getResources().getDrawable(R.id.xxx));

        rl.addItemDecoration(new DividerItemDecoration(MainActivity.this, LinearLayout.VERTICAL));

        adapter.setOnItemClickListener(new ClassAdapter.ItemClickListener() {
            @Override
            public void onItemClick(int position, View view) {

                startActivity(new Intent(MainActivity.this, myClassList.get(position).getClassName()));
            }
        });

//        ForegroundCallbacks.get().addListener(new ForegroundCallbacks.Listener() {
//            @Override
//            public void onBecameForeground() {
//                Toast.makeText(MainActivity.this, "++++App进入前台++++", Toast.LENGTH_SHORT).show();
//            }
//
//            @Override
//            public void onBecameBackground() {
//
//                Toast.makeText(MainActivity.this, "----App退至后台----", Toast.LENGTH_SHORT).show();
//            }
//        });

//        develop合并master 撤销测试
        loggerTest();
    }



    private void loggerTest() {
        Logger.t("apilogger").e("主module logger");
        Logger.t("apilogger").w("wordword");
        Logger.t("apilogger").i("hello logger");
    }



    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getMessageFromJoke(MessageWrap messageEvent) {

        Toast.makeText(this, ""+messageEvent.message, Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
//        System.exit(0);
    }

    long exitTime;
    @Override
    public void onBackPressed() {

        if((System.currentTimeMillis()-exitTime) > 2000){
            Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
            exitTime = System.currentTimeMillis();
        } else {
            super.onBackPressed();
            ActivityStackManager.getInstance().exit();
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    System.exit(0);
                }
            },500);
        }
    }


}
